package cn.zurish.cloud.security.service;

import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
import org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken;

public class CustomPersistentTokenRepository extends JdbcTokenRepositoryImpl {

    @Override
    public void createNewToken(PersistentRememberMeToken token) {
        String encryptedToken = BCrypt.hashpw(token.getTokenValue(), BCrypt.gensalt());
        super.createNewToken(
                new PersistentRememberMeToken(
                        token.getUsername(),
                        token.getSeries(),
                        encryptedToken,
                        token.getDate()
                )
        );
    }
}
